package exercise;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Ex4 {
	public static void main(String[] args) {
		File file1=new File("D:/iotest/Stream.txt");
		OutputStream os=null;
		InputStream  is=null;
		try {
			os=new FileOutputStream(file1);
			is=new FileInputStream(file1);
			String str="I love you!";
//			os.write(str.getBytes());
			for (int i = 0; i < str.length(); i++) {
				os.write((int)str.charAt(i));
			}
			for (int i = 0; i < str.length(); i++) {
				System.out.print((char)is.read());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(os!=null)
				try {
					os.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}

}
